import { Component, OnInit } from '@angular/core';
import {Observable} from "rxjs";
import {User} from "../user";
import {ActivatedRoute, ParamMap} from "@angular/router";
import {UserService} from "../user.service";
import {switchMap} from "rxjs/operators";

@Component({
  selector: 'app-user-detail',
  templateUrl: './user-detail.component.html',
  styleUrls: ['./user-detail.component.css']
})
export class UserDetailComponent implements OnInit {

  user$!: Observable<User>

  constructor(
    private route: ActivatedRoute,
    private userService: UserService,
  ) {
  }


  ngOnInit() {
    this.user$ = this.route.paramMap.pipe(
      switchMap((params: ParamMap) =>
        this.userService.getUser(params.get('id')!))
    );
  }
}
